/**
 * Object.freeze冻结对象
 */
const obj = {
  name: "张三",
  age: 30,
}
Object.freeze(obj); // 冻结obj
obj.name = "李四";
console.info(obj); // {name: "张三", age: 30}
// --------------------------------------------------------------------------------------------
/** 注意：不可以冻结obj，如果value值是object，还是需要freeze。可以通过递归 */
const obj1 = {
  name: "张三",
  age: 30,
  info: {
    sex: 1,
  }
}
function deepFreeze(obj) {
  Object.freeze(obj);
  for(let key in obj) {
    if(obj.hasOwnProperty(key) && typeof obj[key] === "object") {
      deepFreeze(obj[key])
    }
  }
}
deepFreeze(obj1)

obj1.age = 25;
obj1.info.sex = 0;
console.info(obj1) // 结果显示两个值都没有被修改
// --------------------------------------------------------------------------------------------
